n, k = map(int, input().split())
arr = list(map(int, input().split()))
dic = dict()
mod = 1e9 + 7
ans = 0
for i in range(len(arr)):
    ans = (ans + dic.get(arr[i] - k, 0)) % mod
    dic[arr[i]] = (1 + dic.get(arr[i] - k, 0) + dic.get(arr[i], 0)) % mod
print(int(ans))
